package com.lhg.controller;

import com.lhg.common.CommonResult;
import com.lhg.entity.Notice;
import com.lhg.entity.User;
import com.lhg.entity.Vo.AcVo;
import com.lhg.entity.Vo.BarChartVo;
import com.lhg.entity.Vo.PieChartVo;
import com.lhg.service.HomeService;
import com.lhg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HomeController {
    @Autowired
    private HomeService homeService;
    @Autowired
    private UserService userService;

    @GetMapping("/notice/selectAll")
    public CommonResult<?> selectAllNotice() {
        List<Notice> list = homeService.selectAllNotice();
        return CommonResult.success(list);
    }

    @GetMapping("/ac/selectAll")
    public CommonResult<?> selectAllAc(@RequestHeader("Authorization") String authHeader) {
        User foundUser;
        try{
            foundUser = userService.findByAuthorization(authHeader);
        }catch(Exception e){
            return CommonResult.error(401,"jwt验证出错");
        }
        List<AcVo> list = homeService.selectAllAc(foundUser.getId());
        return CommonResult.success(list);
    }

    @GetMapping("/info/sizeCount")
    public CommonResult<?> sizeCount(@RequestHeader("Authorization") String authHeader) {
        User foundUser;
        try{
            foundUser = userService.findByAuthorization(authHeader);
        }catch(Exception e){
            return CommonResult.error(401,"jwt验证出错");
        }
        List<PieChartVo> list = homeService.selectSizeCount(foundUser.getId());
        return CommonResult.success(list);
    }

    @GetMapping("/info/interviewCount")
    public CommonResult<?> interviewCount(@RequestHeader("Authorization") String authHeader) {
        User foundUser;
        try{
            foundUser = userService.findByAuthorization(authHeader);
        }catch(Exception e){
            return CommonResult.error(401,"jwt验证出错");
        }
        List<BarChartVo> list = homeService.interviewCount(foundUser.getId());
        return CommonResult.success(list);
    }

}
